﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.Business.MovingBetweenAreas;
using Inventory.Business.API;
using Inventory.Business;

namespace Inventory.Test
{
    /// <summary>
    /// Summary description for MovingBetweenAreasTest
    /// </summary>
    [TestClass]
    public class AreaMovementTest
    {
        AreaMovement obj = new AreaMovement();
        Inventory.DAL.InventoryEntities inv = new Inventory.DAL.InventoryEntities();

        [TestMethod]
        public void TestGetById()
        {
            var result = obj.GetById(1);

            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void TestMoveMaterials()
        {
            var entity = new Inventory.Business.DomainObjects.AreaMovementEntity()
                {
                    Warehouse = 68,
                    SourceArea = Inventory.Business.DomainObjects.Area.Quarantine,
                    DestinationArea = Inventory.Business.DomainObjects.Area.Inventory
                };

            entity.Materials.Add(new Inventory.Business.DomainObjects.AreaMovementMaterial()
            {
                Id = 19178,
                AvailableQuantity = 1101.5M,
                Quantity = 100,
                Price = 10,
                Comment = "Testing"
            });

            Assert.IsTrue(obj.CreateMovement(entity));
        }

        [TestMethod]
        public void TestMovementEdit()
        {
            var entity = obj.GetById(15);

            //entity.Materials[1].Quantity += 10;
            entity.Materials.RemoveAt(0);

            entity.Materials.Add(new Inventory.Business.DomainObjects.AreaMovementMaterial()
            {
                Id = 19178,
                AvailableQuantity = 1101.5M,
                Quantity = 100,
                Price = 10,
                Comment = "Testing"
            });

            Assert.IsTrue(obj.EditMovement(entity));
        }

        [TestMethod]
        public void TestMovementSubmit()
        {
            var move = obj.GetById(15);

            Assert.IsTrue(obj.SubmitMovement(move));
        }

        [TestMethod]
        public void TestConvert()
        {
            var material = inv.Material.FirstOrDefault();
            var result = obj.Convert(material);

            Assert.IsNotNull(result);
            Assert.AreEqual(material.ID, result.Id);
            Assert.AreEqual(material.Code, result.Code);
            Assert.AreEqual(material.OldCode, result.OldCode);
            Assert.AreEqual(material.Name, result.Name);
        }
    }
}
